<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .box {
            width: 800px;
            height: 100px;
            margin: 20px auto;

        }

        input {
            width: 700px;
            height: 20px;


        }

        button {
            height: 24px;


        }



        li {
            width: 700px;
            height: 25px;
            border: 1px dashed black;
        }

        li+li {
            border-top: 0;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" name="" id="">
        <button>搜索</button>
        <div class="boss">
            <ul>
            </ul>
        </div>
    </div>
    <script>
        var ipt = document.querySelector("input");
        var btn = document.querySelector("button");
        var ul = document.querySelector(".boss ul")
        var script = null
        ipt.oninput = function () {
            var key = ipt.value;
            if (script) {
                script.remove();
            }
            script = document.createElement("script");
            script.src = `https://www.baidu.com/sugrec?prod=pc&wd=${key}&csor=1&cb=haha`
            document.body.appendChild(script)

        }
        function haha(data) {
            // console.log(1);
            var html = ``
            var { g } = data
            console.log(g);
            g.forEach(({ q }) => {
                html += `
                <li><a href="https://www.baidu.com/s?ie=UTF-8&wd=${q}">${q}</a></li>
                `
            })
            ul.innerHTML = html;

        }
    </script>

</body>
<!-- <script src=""></script> -->

</html>